
/**
 * @author murugan.kannan
 *
 */

import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.FileNotFoundException;

import javax.swing.JFrame;

public class Vectors extends Graph implements KeyListener {
int zeroCorrection=scale/2;
float angle=0.0f;
double x=5;
double y=0;
static Vector2D vec;

	public Vectors() {
		//super();
		needSmallLines=false;
		
		vec=new Vector2D(x,y);
	}

	public static void main(String[] args) {

		JFrame f = new JFrame();
		Vectors g = new Vectors();
		// f.add(g);
		f.addKeyListener(g);
		f.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
		f.setBounds(200, 500, s_HEIGHT, s_HEIGHT + size);
		f.getContentPane().add(g);
		f.setVisible(true);

	}
	
	int getGraphX(int x){
		return x*size+zeroCorrection;
	}
	
	int getGraphY(int y){
		return -y*size+zeroCorrection;
	}
	@Override
		public void paint(Graphics g) {

		
		g.setColor(Color.black);
			super.paint(g);
			g.drawLine(getGraphX(0), getGraphY(0), getGraphX((int)x), getGraphY((int)y));
			
			g.fillRect(getGraphX((int)x)-5, getGraphY((int)y)-5, 10, 10);
		vec.x=x;
			vec.y=y;
			int deg=(int)(vec.angle()*100);
			g.drawString(deg/100+"'"+(deg-(deg/100*100)), getGraphX((int)x)+5, getGraphY((int)y)-5);
			//System.out.println(vec.x+"  "+vec.y+"  "+vec.angle()+" | "+vec.mod());
		}

	@Override
	public void keyPressed(KeyEvent e) {
		switch(e.getKeyCode()){
		case KeyEvent.VK_ESCAPE:
			System.exit(0);
			break;
		case KeyEvent.VK_SPACE:
			vec.print();
			break;
			
		case KeyEvent.VK_LEFT:
			x--;
			//y=0;
			break;
		case KeyEvent.VK_RIGHT:
			x++;
			//y=0;
			break;
		case KeyEvent.VK_DOWN:
			y--;
			//y=0;
			break;
		case KeyEvent.VK_UP:
			y++;
			//y=0;
			break;
		case KeyEvent.VK_NUMPAD8:
			vec.incmod(1.0);
			x=vec.x;
			y=vec.y;
			
			break;
		}
		
	}

	@Override
	public void keyReleased(KeyEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void keyTyped(KeyEvent arg0) {
		// TODO Auto-generated method stub
		
	}
}
